package DirectoryViewer;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * User: Андрей
 * Date: 10.12.13
 * Time: 20:28
 * To change this template use File | Settings | File Templates.
 */
public class find implements ICommandExecutor
{
           public void execute(String str)
           {
               String path="";
               String searchingFile="";
               for(int i=0;i<str.length();i++)
               {
                   if(str.charAt(i)==' ')
                   {
                        path=str.substring(0,i);
                       searchingFile=str.substring(i+1,str.length());
                   }
               }
               File f=new File(path);
               ArrayList<File> files = new ArrayList<File>(Arrays.asList(f.listFiles()));
               for(File item:files)
               {
                   if(item.getName().contains(searchingFile))
                   {
                       new SimpleDateFormat("dd-MM-yyyy HH-mm-ss").format(new Date(item.lastModified()));
                       if(item.isDirectory()) {
                           System.out.println("<dir> "+item.getName()+" размер "+(double)item.length()/1024+" кб, "+"дата обновления "+new SimpleDateFormat("dd-MM-yyyy HH-mm-ss").format(new Date(item.lastModified())));
                       }
                       if(item.isFile()) {
                           System.out.println("<file> "+item.getName()+" размер "+(double)item.length()/1024+" кб, "+"дата обновления "+new SimpleDateFormat("dd-MM-yyyy HH-mm-ss").format(new Date(item.lastModified())));
                       }
                   }
               }
           }
}
